<template>
  <div>
    <h4>治疗记录</h4>
    <el-form :model="form" label-width="100px">
      <!-- <el-form-item label="用药/治疗">
        <el-radio-group v-model="form.useMedication" @change="handleUseMedication">
          <el-radio :label="1">有</el-radio>
          <el-radio :label="2">无</el-radio>
        </el-radio-group>
      </el-form-item> -->
      <el-form-item label="MG药物治疗:">
        <el-checkbox-group
          v-model="form.mgDrugTreatment"
          @change="handleMgTreatment"
        >
          <el-checkbox label="1" name="mgTreatment">溴吡斯的明</el-checkbox>
          <el-checkbox label="2" name="mgTreatment">醋酸泼尼松</el-checkbox>
          <el-checkbox label="3" name="mgTreatment">甲泼尼龙</el-checkbox>
          <el-checkbox label="4" name="mgTreatment">硫唑嘌呤</el-checkbox>
          <el-checkbox label="5" name="mgTreatment">他克莫司</el-checkbox>
          <el-checkbox label="6" name="mgTreatment">环孢素A</el-checkbox>
          <el-checkbox label="7" name="mgTreatment">吗替麦考酚酯</el-checkbox>
          <el-checkbox label="8" name="mgTreatment">甲氨蝶呤</el-checkbox>
          <el-checkbox label="9" name="mgTreatment">环磷酰胺</el-checkbox>
          <el-checkbox label="10" name="mgTreatment">注射用甲泼尼龙琥珀酸钠</el-checkbox>
          <el-checkbox label="11" name="mgTreatment">利妥昔单抗</el-checkbox>
          <el-checkbox label="12" name="mgTreatment">中药</el-checkbox>
          <el-checkbox label="13" name="mgTreatment">丙种球蛋白</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <mg-treatment-detail
        v-for="item in titles"
        :key="item.id"
        :ref="'drug'+item.id"
        :title="item.title"
        :title4="item.title4"
        :title5="item.title5"
        :title7="item.title7"
        :show="isShow(item.id)"
        :show1="isShow1(item.id)"
      />
      <el-form-item label="MG免疫治疗">
        <el-radio-group
          v-model="form.mgImmuneTreatment"
          @change="handleMgImmunotherapy"
        >
          <el-radio :label="1">有</el-radio>
          <el-radio :label="2">无</el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-show="mgImmunotherapyValue === 1">
        <mgImmunotherapy ref="mgImmunotherapy" />
      </div>
      <el-form-item label="胸腺手术治疗">
        <el-radio-group
          v-model="form.thymicSurgeryTreatment"
          @change="handleThymicSurgery"
        >
          <el-radio :label="1">有</el-radio>
          <el-radio :label="2">无</el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-show="thymicSurgeryValue === 1">
        <el-divider />
        <h4>胸腺手术史</h4>

        <thymus-operation
          v-show="thymicSurgeryValue === 1"
          ref="thymicSurgeryHistory"
        />
      </div>
      <el-form-item label="其他治疗">
        <el-radio-group
          v-model="form.otherTreatment"
          @change="handleOtherTreatment"
        >
          <el-radio :label="1">有</el-radio>
          <el-radio :label="2">无</el-radio>
        </el-radio-group>
      </el-form-item>

      <div v-show="otherTreatmentValue === 1">
        <other ref="other" />
      </div>

      <el-button type="primary" @click="onSubmit">保存</el-button>
    </el-form>
  </div>
</template>

<script>
import ThymusOperation from './thymusOperation.vue'
import mgTreatmentDetail from './mgTreatmentDetail.vue'
import other from './other.vue'
import mgImmunotherapy from './mgImmunotherapy.vue'
import { add } from '@/api/baselineTreatment'
import { initData } from '@/api/data'

export default {
  components: {
    ThymusOperation,
    mgTreatmentDetail,
    other,
    mgImmunotherapy
  },
  data() {
    return {
      form: {
        pid: this.pId,
        mgDrugTreatment: [],
        mgImmuneTreatment: 0,
        thymicSurgeryTreatment: 0,
        otherTreatment: 0
      },
      query: {
        pid: this.pId
      },
      params: {
        drug: [],
        drimmunosuppressiveg: [],
        baselineTreatment: {},
        otherTreatment: {},
        mgImmuneTreatment: {},
        thymicSurgeryHistory: {}
      },
      useMedicationValue: 0,
      thymicSurgeryValue: 0,
      otherTreatmentValue: 0,
      mgImmunotherapyValue: 0,
      thymicSurgeryHistory: 0,
      titles: [
        {
          id: '1',
          title: '溴吡斯的明'
        },
        {
          id: '2',
          title: '醋酸泼尼松'
        },
        {
          id: '3',
          title: '甲泼尼龙'
        },
        {
          id: '4',
          title: '硫唑嘌呤'
        },
        {
          id: '5',
          title: '他克莫司'
        },
        {
          id: '6',
          title: '环孢素A'
        },
        {
          id: '7',
          title: '吗替麦考酚酯'
        },
        {
          id: '8',
          title: '甲氨蝶呤'
        },
        {
          id: '9',
          title: '环磷酰胺'
        },
        {
          id: '10',
          title: '注射用甲泼尼龙琥珀酸钠',
          title4: '使用剂量（mg）',
          title5: '使用时间',
          title7: '使用剂量（mg）'
        },
        {
          id: '11',
          title: '利妥昔单抗',
          title4: '使用剂量（mg）',
          title5: '使用时间',
          title7: '使用剂量（mg）'
        },
        {
          id: '12',
          title: '中药'
        },
        {
          id: '13',
          title: '丙种球蛋白'
        }
      ],
      mgTreatmentValue: []
    }
  },
  inject: ['pId'],
  created() {
    initData('/api/baselineTreatment/queryByPid', this.query).then((res) => {
      if (JSON.stringify(res) === '{}') {
        console.log(res)
        return
      }
      console.log(res)
      this.form = res.baselineTreatment
      this.thymicSurgeryValue = res.baselineTreatment.thymicSurgeryTreatment
      this.otherTreatmentValue = res.baselineTreatment.otherTreatment
      this.mgImmunotherapyValue = res.baselineTreatment.mgImmuneTreatment
      this.mgTreatmentValue = res.baselineTreatment.mgDrugTreatment
      for (const value in res.baselineTreatment.mgDrugTreatment) {
        switch (res.drug[value].dId) {
          case 1:
            this.$refs.drug1[0].form = res.drug[value]
            break
          case 2:
            this.$refs.drug2[0].form = res.drug[value]
            break
          case 3:
            this.$refs.drug3[0].form = res.drug[value]
            break
          case 4:
            this.$refs.drug4[0].form = res.drug[value]
            break
          case 5:
            this.$refs.drug5[0].form = res.drug[value]
            break
          case 6:
            this.$refs.drug6[0].form = res.drug[value]
            break
          case 7:
            this.$refs.drug7[0].form = res.drug[value]
            break
          case 8:
            this.$refs.drug8[0].form = res.drug[value]
            break
          case 9:
            this.$refs.drug9[0].form = res.drug[value]
            break
          case 10:
            this.$refs.drug10[0].form = res.drug[value]
            break
          case 11:
            this.$refs.drug11[0].form = res.drug[value]
            break
          case 12:
            this.$refs.drug12[0].form = res.drug[value]
            break
          case 13:
            this.$refs.drug13[0].form = res.drug[value]
            break
        }
      }
      if (res.baselineTreatment.otherTreatment === 1) {
        this.$refs.other.form = res.otherTreatment
      }
      if (res.baselineTreatment.mgImmuneTreatment === 1) {
        this.$refs.mgImmunotherapy.form = res.mgImmuneTreatment
      }
      if (res.baselineTreatment.thymicSurgeryTreatment === 1) {
        console.log(res.thymicSurgeryHistory)
        this.$refs.thymicSurgeryHistory.form.crisis = res.thymicSurgeryHistory.crisis
        this.$refs.thymicSurgeryHistory.form.thymicSurgeryTime = res.thymicSurgeryHistory.thymicSurgeryTime
        this.$refs.thymicSurgeryHistory.form.timeInterval = res.thymicSurgeryHistory.timeInterval
        this.$refs.thymicSurgeryHistory.form.crisisTimes = res.thymicSurgeryHistory.crisisTimes
        this.$refs.thymicSurgeryHistory.form.mgfa = res.thymicSurgeryHistory.mgfa
        this.$refs.thymicSurgeryHistory.form.sphericalMuscle = res.thymicSurgeryHistory.sphericalMuscle
        this.$refs.thymicSurgeryHistory.form.preoperativeMedication = res.thymicSurgeryHistory.preoperativeMedication
        this.$refs.thymicSurgeryHistory.form.medicationType = res.thymicSurgeryHistory.medicationType
        this.$refs.thymicSurgeryHistory.form.dose = res.thymicSurgeryHistory.dose
        this.$refs.thymicSurgeryHistory.form.preoperativeUseTime = res.thymicSurgeryHistory.preoperativeUseTime
        this.$refs.thymicSurgeryHistory.form.immunosuppressive = res.thymicSurgeryHistory.immunosuppressive
        this.$refs.thymicSurgeryHistory.form.bingQiu = res.thymicSurgeryHistory.bingQiu
        this.$refs.thymicSurgeryHistory.form.hormone = res.thymicSurgeryHistory.hormone
        this.$refs.thymicSurgeryHistory.form.plasma = res.thymicSurgeryHistory.plasma
        this.$refs.thymicSurgeryHistory.form.feiGong = res.thymicSurgeryHistory.feiGong
        this.$refs.thymicSurgeryHistory.form.fcv = res.thymicSurgeryHistory.fcv
        this.$refs.thymicSurgeryHistory.form.fev1 = res.thymicSurgeryHistory.fev1
        this.$refs.thymicSurgeryHistory.form.muscleWeakness = res.thymicSurgeryHistory.muscleWeakness
        this.$refs.thymicSurgeryHistory.form.surgicalApproach = res.thymicSurgeryHistory.surgicalApproach
        this.$refs.thymicSurgeryHistory.form.surgery = res.thymicSurgeryHistory.surgery
        this.$refs.thymicSurgeryHistory.form.scope = res.thymicSurgeryHistory.scope
        this.$refs.thymicSurgeryHistory.form.surgicalDuration = res.thymicSurgeryHistory.surgicalDuration
        this.$refs.thymicSurgeryHistory.form.loseWeight = res.thymicSurgeryHistory.loseWeight
        this.$refs.thymicSurgeryHistory.form.muscleWeaknessAfter = res.thymicSurgeryHistory.muscleWeaknessAfter
        this.$refs.thymicSurgeryHistory.form.complication = res.thymicSurgeryHistory.complication
        this.$refs.thymicSurgeryHistory.form.pathology = res.thymicSurgeryHistory.pathology
        this.$refs.thymicSurgeryHistory.form.name = res.thymicSurgeryHistory.name
        this.$refs.thymicSurgeryHistory.form.pathology = res.thymicSurgeryHistory.pathology
        for (const index in res.thymicSurgeryHistory.immunosuppressive) {
          switch (parseInt(res.immunosuppressive[index].dName)) {
            case 1:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive1[0].form = res.immunosuppressive[index]
              break
            case 2:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive2[0].form = res.immunosuppressive[index]
              break
            case 3:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive3[0].form = res.immunosuppressive[index]
              break
            case 4:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive4[0].form = res.immunosuppressive[index]
              break
            case 5:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive5[0].form = res.immunosuppressive[index]
              break
            case 6:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive6[0].form = res.immunosuppressive[index]
              break
            case 7:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive7[0].form = res.immunosuppressive[index]
              break
            case 8:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive8[0].form = res.immunosuppressive[index]
              break
            case 9:
              this.$refs.thymicSurgeryHistory.$refs.immunosuppressive9[0].form = res.immunosuppressive[index]
              break
          }
        }
      }
    })
  },
  methods: {
    onSubmit() {
      this.$refs.drug1[0].form.dId = 1
      this.$refs.drug2[0].form.dId = 2
      this.$refs.drug3[0].form.dId = 3
      this.$refs.drug4[0].form.dId = 4
      this.$refs.drug5[0].form.dId = 5
      this.$refs.drug6[0].form.dId = 6
      this.$refs.drug7[0].form.dId = 7
      this.$refs.drug8[0].form.dId = 8
      this.$refs.drug9[0].form.dId = 9
      this.$refs.drug10[0].form.dId = 10
      this.$refs.drug11[0].form.dId = 11
      this.$refs.drug12[0].form.dId = 12
      this.$refs.drug13[0].form.dId = 13
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive1[0].form.dName = 1
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive2[0].form.dName = 2
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive3[0].form.dName = 3
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive4[0].form.dName = 4
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive5[0].form.dName = 5
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive6[0].form.dName = 6
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive7[0].form.dName = 7
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive8[0].form.dName = 8
      this.$refs.thymicSurgeryHistory.$refs.immunosuppressive9[0].form.dName = 9
      this.params.drug = []
      this.params.drug.push(this.$refs.drug1[0].form)
      this.params.drug.push(this.$refs.drug2[0].form)
      this.params.drug.push(this.$refs.drug3[0].form)
      this.params.drug.push(this.$refs.drug4[0].form)
      this.params.drug.push(this.$refs.drug5[0].form)
      this.params.drug.push(this.$refs.drug6[0].form)
      this.params.drug.push(this.$refs.drug7[0].form)
      this.params.drug.push(this.$refs.drug8[0].form)
      this.params.drug.push(this.$refs.drug9[0].form)
      this.params.drug.push(this.$refs.drug10[0].form)
      this.params.drug.push(this.$refs.drug11[0].form)
      this.params.drug.push(this.$refs.drug12[0].form)
      this.params.drug.push(this.$refs.drug13[0].form)
      this.params.immunosuppressive = []
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive1[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive2[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive3[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive4[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive5[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive6[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive7[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive8[0].form)
      this.params.immunosuppressive.push(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive9[0].form)
      this.params.baselineTreatment = this.form
      this.params.otherTreatment = this.$refs.other.form
      this.params.mgImmuneTreatment = this.$refs.mgImmunotherapy.form
      this.params.thymicSurgeryHistory = this.$refs.thymicSurgeryHistory.form
      console.log(this.form)
      console.log(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive1)
      console.log(this.$refs.thymicSurgeryHistory.$refs.immunosuppressive6)
      console.log(this.$refs.thymicSurgeryHistory.form)
      add(this.params).then((res) => {
        alert('success')
      })
    },
    handleUseMedication(v) {
      this.useMedicationValue = v
    },
    handleThymicSurgery(v) {
      this.thymicSurgeryValue = v
    },
    handleOtherTreatment(v) {
      this.otherTreatmentValue = v
    },
    handleMgImmunotherapy(v) {
      this.mgImmunotherapyValue = v
    },
    handleThymicSurgeryHistory(v) {
      this.thymicSurgeryHistory = v
    },
    isShow(key) {
      return this.mgTreatmentValue.indexOf(key) !== -1
    },
    handleMgTreatment(v) {
      this.mgTreatmentValue = v
    },
    isShow1(key) {
      if (key === '10' || key === '11') {
        return false
      }
      return true
    }
  }
}
</script>

<style>
</style>
